using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

using GURUCORE.Framework.DataAccess;

namespace GURUCORE.Framework.Business
{
    /// <summary>
    /// This type of Application load Service config
    /// </summary>
	public class ServiceOrientedApplication : DataAccessApplication
	{
		public override void Start(object p_oParam)
		{
			string sRootDir = (string)p_oParam;
			string sConfigDir = sRootDir + "/Config";

			base.Start(p_oParam);

			try
			{
				//load system's service factory
				ServiceFactory oSvcFactory = new ServiceFactory(sConfigDir + "/System/Service.config");
				//load all module's service factory
				DirectoryInfo oDirInfo = new DirectoryInfo(sConfigDir);
				FileInfo[] arrFile = oDirInfo.GetFiles("Service.config", SearchOption.AllDirectories);
				foreach (FileInfo oFile in arrFile)
				{
					if (!oFile.Directory.Name.EndsWith("System"))
					{
						ServiceFactory oModuleDSFactory = new ServiceFactory(oFile.FullName);
						oSvcFactory.Merge(oModuleDSFactory);
					}
				}

				this.AddSharedObject(ServiceFactory.GLOBAL_CACHE_KEY, oSvcFactory);
			}
			catch (Exception ex)
			{
				ex.ToString();
				//no service defined
			}
		}
	}
}
